import { ajax } from '@/utils'

import { ExpressTempleteItem } from './jindouGiftTypes'
import type {
  GetCommodityDetailRes,
  GetExchangeCommodityDetailRes,
  GetExchangeCommodityListRes,
  GetExchangeRecordListRes,
  GetGroupConfigRes,
  GetGroupItemDetailRes,
  GetGroupListRes,
  GetGroupManageItemDetailRes,
  GetGroupManageListRes,
  GetSignInRecordListRes,
  GetSignInSettingRes,
  RulesListItem,
  YxGiftGoodsItem,
  YxOrderDetail
} from './marketingTypes'

const baseUrl = '/yswy-zy-activity'

export default {
  /** 获取兑换记录 */
  getExchangeRecordList(data): Promise<GetExchangeRecordListRes> {
    return ajax.post(`${baseUrl}/exchangePointGoodsRecord/list`, data)
  },
  /** 导出兑换记录 */
  exportExchangeRecordList(data) {
    return ajax.post(`${baseUrl}/exchangePointGoodsRecord/export`, data, {
      withResponse: true,
      responseType: 'blob'
    })
  },
  /** 获取兑换商品记录 */
  getExchangeCommodityList(data): Promise<GetExchangeCommodityListRes> {
    return ajax.post(`${baseUrl}/pointGoods/list2`, data)
  },
  /** 上架商品 */
  upCommodity(id: number) {
    return ajax.post(`${baseUrl}/pointGoods/up2/${id}`)
  },
  /** 下架商品 */
  downCommodity(id: number) {
    return ajax.post(`${baseUrl}/pointGoods/down2/${id}`)
  },
  /** 获取兑换商品详情 */
  getExchangeCommodityDetail(
    id: number
  ): Promise<GetExchangeCommodityDetailRes> {
    return ajax.get(`${baseUrl}/pointGoods/detail/${id}`)
  },
  /** 添加兑换商品 */
  createExchangeCommodity(data) {
    return ajax.post(`${baseUrl}/pointGoods/create`, data)
  },
  /** 更新兑换商品详情 */
  updateExchangeCommodityDetail(data) {
    return ajax.put(`${baseUrl}/pointGoods/edit`, data)
  },
  /** 获取商品详情 */
  getCommodityDetail(id: number): Promise<GetCommodityDetailRes> {
    return ajax.get(`${baseUrl}/pointGoodsDetail/detail/${id}`)
  },
  /** 创建商品详情 */
  createCommodityDetail(data) {
    return ajax.post(`${baseUrl}/pointGoodsDetail/create`, data)
  },
  /** 更新商品详情 */
  updateCommodityDetail(data) {
    return ajax.post(`${baseUrl}/pointGoodsDetail/edit`, data)
  },
  /** 删除兑换商品列表 */
  deleteExchangeCommodityList(ids: number[]) {
    return ajax.delete(`${baseUrl}/pointGoods/del`, { data: { ids } })
  },
  /** 获取签到记录列表 */
  getSignInRecordList(data): Promise<GetSignInRecordListRes> {
    return ajax.post(`${baseUrl}/back/sign/member/listByPage`, data)
  },
  /** 导出签到记录列表 */
  exportSignInRecordList(data) {
    return ajax.post(`${baseUrl}/back/sign/member/exportExcel`, data, {
      withResponse: true,
      responseType: 'blob'
    })
  },
  /** 获取签到配置 */
  getSignInSetting(): Promise<GetSignInSettingRes> {
    return ajax.get(`${baseUrl}/back/sign/searchSignSetting`)
  },
  /** 更新签到配置 */
  updateSignInSetting(data) {
    return ajax.post(`${baseUrl}/back/sign/updateSignSetting`, data)
  },
  /** 获取拼团管理列表 */
  getGroupManageList(data): Promise<GetGroupManageListRes> {
    return ajax.post(`${baseUrl}/amalgamateGroup/list`, data)
  },
  /** 发布拼团 */
  publishGroupMangeItem(id: number) {
    return ajax.post(`${baseUrl}/amalgamateGroup/publish/${id}`)
  },
  /** 下架拼团 */
  rackGroupManageItem(id: number) {
    return ajax.post(`${baseUrl}/amalgamateGroup/over/${id}`)
  },
  /** 获取拼团详情 */
  getGroupManageItemDetail(id: number): Promise<GetGroupManageItemDetailRes> {
    return ajax.get(`${baseUrl}/amalgamateGroup/detail/${id}`)
  },
  /** 创建拼团 */
  createGroupManageItem(data) {
    return ajax.post(`${baseUrl}/amalgamateGroup/create`, data)
  },
  /** 更新拼团 */
  updateGroupManageItem(data) {
    return ajax.put(`${baseUrl}/amalgamateGroup/edit`, data)
  },
  /** 复制拼团 */
  cloneGroupManageItem(id: number) {
    return ajax.put(`${baseUrl}/amalgamateGroup/copy/${id}`)
  },
  /** 获取拼团列表 */
  getGroupList(data): Promise<GetGroupListRes> {
    return ajax.post(`${baseUrl}/amalgamateGroup/groupList`, data)
  },
  /** 获取拼团详情 */
  getGroupItemDetail(id: number): Promise<GetGroupItemDetailRes> {
    return ajax.get(`${baseUrl}/amalgamateGroup/groupInfo`, { params: { id } })
  },
  /** 获取拼团配置 */
  getGroupConfig(): Promise<GetGroupConfigRes> {
    return ajax.get(`${baseUrl}/groupConfig/back/getGroupConfigDetail`)
  },
  /** 更新拼团配置 */
  updateGroupConfig(data) {
    return ajax.post(`${baseUrl}/groupConfig/back/updateGroupConfig`, data)
  },

  /** 运费模板列表 */
  getExpressTempleteList(data): Promise<any> {
    return ajax.post(`${baseUrl}/transitTemplate/list`, data)
  },
  /** 新增运费模板*/
  addExpressTemplete(data): Promise<any> {
    return ajax.post(`${baseUrl}/transitTemplate/add`, data)
  },
  /** 编辑运费模板*/
  editExpressTemplete(data): Promise<any> {
    return ajax.put(`${baseUrl}/transitTemplate/edit`, data)
  },
  /** 启用/禁用运费模板*/
  upDownExpressTemplete(id): Promise<any> {
    return ajax.post(`${baseUrl}/transitTemplate/upDown/${id}`)
  },
  /** 选择运费模板列表*/
  getSelectExpressTempleteList(): Promise<ExpressTempleteItem[]> {
    return ajax.get(`${baseUrl}/transitTemplate/simpleList`)
  },

  /** 商品列表列表*/
  getGoodsList(data): Promise<any> {
    return ajax.post(`${baseUrl}/goodsManage/list`, data)
  },
  /** 上架/下架运商品*/
  upDownGoods(ids, status): Promise<any> {
    return ajax.put(`${baseUrl}/goodsManage/batchUpDown`, { ids, status })
  },
  /** 手动同步*/
  goodsSync(): Promise<any> {
    return ajax.post(`${baseUrl}/goodsManage/sync/spec`)
  },
  /** 获取商品详情*/
  getGoodsDetail(id): Promise<YxGiftGoodsItem> {
    return ajax.get(`${baseUrl}/goodsManage/detail/${id}`)
  },
  /** 新增商品*/
  addGoods(data): Promise<any> {
    return ajax.post(`${baseUrl}/goodsManage/create`, data)
  },
  /** 编辑商品*/
  editGoods(data): Promise<any> {
    return ajax.put(`${baseUrl}/goodsManage/edit`, data)
  },
  /** 禁用启用规格商品*/
  upDownSku(id): Promise<any> {
    return ajax.post(`${baseUrl}/goodsManage/disableSpec/${id}`)
  },

  /** 同步Erp商品*/
  syncSkuErpStock(id): Promise<any> {
    return ajax.get(`${baseUrl}/goodsManage/skuErpStockSync/${id}`)
  },

  /** 订单列表 */
  getOrderList(data): Promise<any> {
    return ajax.post(`${baseUrl}/pointGoodsOrder/list`, data)
  },
  /** 导出订单 */
  exportOrderList(data) {
    return ajax.post(`${baseUrl}/pointGoodsOrder/export`, data, {
      withResponse: true,
      responseType: 'blob'
    })
  },
  /** 订单详情 */
  getOrderDetail(orderNo): Promise<YxOrderDetail> {
    return ajax.get(`${baseUrl}/pointGoodsOrder/detail/${orderNo}`)
  },
  /** 售后 */
  afterSales(orderNo, amount): Promise<any> {
    return ajax.post(
      `${baseUrl}/pointGoodsOrder/afterSale/${orderNo}/${amount}`
    )
  },
  /** 售后订单列表 */
  getRefundList(data): Promise<any> {
    return ajax.post(`${baseUrl}/pointRefund/list`, data)
  },
  /** 快递查看列表 */
  getExpressionShow(data): Promise<any> {
    return ajax.post(`${baseUrl}/change/expression/show`, data)
  },
  /** 快递更换列表 */
  getExpressionList(data): Promise<any> {
    return ajax.post(`${baseUrl}/change/expression/list`, data)
  },
  /** 快递确认导入 */
  getExpressionImport(data): Promise<any> {
    return ajax.post(`${baseUrl}/change/expression/import`, data)
  },
  /** 上传文件确认弹窗 */
  getImportInfo(data): Promise<any> {
    return ajax.post(`${baseUrl}/change/expression/import/info`, data)
  },

  /** 物流详情 */
  getExpressDetail(orderNo): Promise<any> {
    return ajax.get(`${baseUrl}/pointGoodsOrder/transit/${orderNo}`)
  },

  /** 上架的列表 */
  getUpGoodsList(data): Promise<any> {
    return ajax.post(`${baseUrl}/goodsManage/upGoods`, data)
  },
  /** 上架的Sku列表 */
  getUpSkuList(id): Promise<any> {
    return ajax.get(`${baseUrl}/goodsManage/upGoodsSpecs?id=${id}`)
  },
  /** 直播预约规则详情 */
  getRulesList(): Promise<RulesListItem> {
    return ajax.post(`${baseUrl}/liveBookingBanner/detail`)
  },
  /** 编辑直播预约Banner */
  editBannerTemplete(data): Promise<any> {
    return ajax.post(`${baseUrl}/liveBookingBanner/edit`, data)
  }
}
